package com;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class DBconfig {
    private static volatile MysqlDataSource datasource;
     public static Connection getDatasource() throws SQLException {
        if (datasource==null){
            synchronized (DBconfig.class){
                if (datasource==null){
                    datasource.setServerName("127.0.0.1");
                    datasource.setDatabaseName("java20210125");
                    datasource.setPort(3306);
                    datasource.setUser("root");
                    datasource.setPassword("missh111");
                    datasource.setUseSSL(false);
                    datasource.setCharacterEncoding("utf8");
                }
            }
        }
    return datasource.getConnection();
    }
}
